home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rjs.lha / RJS / Transport / src / UnixAddress.C < prev    next >
C/C++ Source or Header  |  1991-06-14  |  1KB  |  62 lines

  1.  
  2. #include <stdio.h>
  3. #include <osfcn.h>
  4. #include <libc.h>
  5. #include <errno.h>
  6. #include <string.h>
  7. #include <netdb.h>
  8. #include <iostream.h>
  9.  
  10. #include "Transport.h"
  11.  
  12. extern "C" {
  13.     unsigned long htonl(unsigned long);
  14.     unsigned short htons(unsigned short);
  15.     unsigned short ntohs(unsigned short);
  16.     struct hostent *gethostbyname(const char *host);
  17. }
  18.  
  19. char *RJS_UnixAddress::Temp="";
  20.  
  21. const RJS_Status RJS_UnixAddress::NoPathGiven("no path given");
  22.  
  23. ostream &operator<<(ostream &os, const RJS_UnixAddress &ia)
  24. {
  25.     os << "(" << ia.pathname() << ")";
  26.     return os;
  27. }
  28.  
  29. RJS_UnixAddress::RJS_UnixAddress() 
  30. {
  31.     ss_set(NoPathGiven);
  32.     addrlen=sizeof(address);
  33.     bzero((char *) &address, sizeof(address));
  34.     address.sun_family = RJS_Socket::AfUnix;
  35.     strcpy(address.sun_path,"");
  36.     addrlen = sizeof(address.sun_family);
  37. }
  38.  
  39. RJS_UnixAddress::RJS_UnixAddress(const char *pathname)
  40. {
  41. set(pathname);
  42. }
  43.  
  44. void RJS_UnixAddress::set(const char *pathname)
  45. {
  46.   bzero((char *) &address, sizeof(address));
  47.   address.sun_family = RJS_Socket::AfUnix;
  48.   if (pathname==Temp) {
  49.     strcpy(address.sun_path,tmpnam(NULL));
  50.   } else strcpy(address.sun_path,pathname);
  51.  
  52.   addrlen = strlen(pathname) + sizeof(address.sun_family);
  53.  
  54. }
  55.  
  56. const char *RJS_UnixAddress::pathname() const
  57. {
  58.     address.sun_path[addrlen-sizeof(address.sun_family)] = 0;
  59.     return address.sun_path;
  60. }
  61.  
  62.